package com.faithbj.common.model;

import java.io.Serializable;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;

import com.faithbj.common.utils.DateUtils;

/**
 * 自定义主键
 * @author xyuser
 *
 */
//@Component("customIncrement")
public class CustomIncrement implements IdentifierGenerator{

	static final Logger logger = Logger.getLogger(CustomIncrement.class.getName());
	
	@Override
	synchronized 
	public Serializable generate(SessionImplementor session, Object object)
			throws HibernateException {
		StringBuilder id=new StringBuilder();
		id.append("D204A00").append(DateUtils.getCurrentDateString("yyyyMMddHHmmssssss")).append(UUID.randomUUID().toString().toUpperCase().substring(0,7));
		
		logger.debug("mamual:id generated");
		
		return id.toString();
	}

}
